package com.lee.chain.service;

/**
 * @author zfl_a
 * @Desc 根据级别来记录不同操作日志的handler
 * @date 2020/8/11
 * @project springboot_design_pattern
 */
public abstract class AbstractLoggerHandler {

    protected int level ;

    protected AbstractLoggerHandler abstractLoggerHandler;

    public void setAbstractLoggerHandler(AbstractLoggerHandler abstractLoggerHandler){
        this.abstractLoggerHandler = abstractLoggerHandler ;
    }
    
    public void logMessage(int level,String message) {
        if(this.level<=level) {
            saveLogMessage(message);
        } else if(abstractLoggerHandler != null && this.level>level && abstractLoggerHandler.abstractLoggerHandler!=null) {
            System.out.println("无log处理器处理，请自定义默认处理器处理");
            return ;
        }
        //如果还有下一个处理器，继续调用，在各个处理器中，需要注意不存在的级别情况s
        if(abstractLoggerHandler!=null) {
            abstractLoggerHandler.logMessage(level,message);
        }
    }

    protected abstract void saveLogMessage(String message);

}
